package dao;

import domain.Teacher;

import java.util.ArrayList;

public class TeacherDao {
    private ArrayList<Teacher>list= new ArrayList<>();

    public void delete(String sid) {
       int index= getIndex(sid);
       list.remove(index);
    }
    public  int getIndex(String sid){
        for (int i = 0; i < list.size(); i++) {
            Teacher teacher = list.get(i);
            if (teacher.getSid().equals(sid)){
                return i;
            }
        }
        return -1;
    }

    public void addteacher(Teacher teacher) {
        list.add(teacher);
    }

    public ArrayList<Teacher> find() {
        return list;
    }

    public void update(String sid, Teacher teacher) {
        int index = getIndex(sid);
        list.set(index,teacher);
    }
}
